* Reset settings and initialize log file
launch, path("share/annuals")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Calculate women's annual EPOP and LFPR under counterfactuals
*              where summer work activity holds at May levels.
*-------------------------------------------------------------------------------


* Prepare data and run models
*-------------------------------------------------------------------------------

* Prepare labor measures among (1) all adults and (2) parents of kids aged 6-12
gzuse "$basepath/data/derived/cps_bms_sample.dta.gz", clear
keep pid tm month wtfinl tmspline* weeks female youngest emp lfp
expand = 2, gen(k)
keep if k == 0 | (k == 1 & youngest == 2)
gen group = ""
replace group = "all" if k == 0
replace group = "parents" if k == 1
gcollapse (mean) emp lfp (rawsum) wtfinl (first) month tmspline* weeks [pw = wtfinl], by(female group tm)
tempfile core
save `core', replace

* Run regressions
if "$estimate" != "0" {
	* Loop over sex and parental status
	foreach f of numlist 0 1 {
		foreach g in "all" "parents" {
			* Load sample
			use if female == `f' & group == "`g'" using `core', clear
			tsset tm

			* Run specifications
			foreach v in emp lfp {
				quietly ivreg2 `v' ib5.month tmspline* weeks [aw = wtfinl], bw($bandwidth) robust small
				process_estimates, path("annuals") model("f`f'_`g'_`v'")
			}
		}
	}
}


* Prepare estimates
*-------------------------------------------------------------------------------

* Load estimates into memory
load_estimates, path("annuals")

* Prepare coefficient labels for each month
make_coeflabels


* Construct counterfactuals
*-------------------------------------------------------------------------------

* Reload data on EPOP and LFPR
use `core', clear

* Compute counterfactual EPOP and LFPR by setting summer equal to May values
gen emp_cf = emp
gen lfp_cf = lfp

foreach f of numlist 0 1 {
	foreach g in "all" "parents" {
		foreach v in "emp" "lfp" {
			* Load estimates
			estimates restore f`f'_`g'_`v'

			* Set variable equal to May levels
			replace `v'_cf = `v'_cf - _b[coef1] if female == `f' & group == "`g'" & month == 6
			replace `v'_cf = `v'_cf - _b[coef2] if female == `f' & group == "`g'" & month == 7
			replace `v'_cf = `v'_cf - _b[coef3] if female == `f' & group == "`g'" & month == 8
		}
	}
}

* Express percentages in percent terms
foreach v of varlist emp* lfp* {
	replace `v' = 100 * `v'
}

* Take annual averages
gcollapse (mean) emp* lfp*, by(female group)

* Report gaps
gen emp_gap = emp_cf - emp
gen lfp_gap = lfp_cf - lfp

format %9.3f emp* lfp*
order female group emp* lfp*
list

* Close the log file
unlaunch
